<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:c="http://java.sun.com/jsp/jstl/core">
    <h:head>
        <link rel="shortcut icon" href="images/favicon.ico"/>
        <title>JForum :: #{resourcesController.extractResource('THREAD_VIEW')}</title>
    </h:head>
    <h:body style="background-color: #111111">

      <div id="header">
		<ui:insert name="header" >
			<ui:include src="header.xhtml" />
		</ui:insert>
      </div>

      <center>
         <h:form>
           
           <p:dataTable  var="post"
                         value="#{forumPostsBean.getPosts()}"
                         id="posts"
                         liveScroll="true"
                         style="width: 790px"
                         paginator="true" rows="10"
                         paginatorTemplate="{CurrentPageReport} {PreviousPageLink} {PageLinks} {NextPageLink} {RowsPerPageDropdown}"
                         rowsPerPageTemplate="5,10,15">
               
                <f:facet name="header">
                    <h:outputLabel value="#{forumPostsBean.currentThread.name}"/>
                </f:facet>

                <p:column style="vertical-align: top">
                    <f:facet name="header">
                        <h:outputText value="#{resourcesController.extractResource('AUTHOR')}" />
                    </f:facet>

                    <div align="center" >
                        <h:outputText value="#{post.author}" />
                        <br/>    
                        <p:graphicImage url="#{forumPostsBean.retrieveAvatarPath(post.author)}"
                                        width="75"
                                        style="border-color: black"/>
                                 
                    </div>
                </p:column>

                <p:column>
                    <f:facet name="header">
                        <h:outputText value="#{resourcesController.extractResource('MESSAGE')}" />
                    </f:facet>
                    <p:panel style="width: 500px; word-wrap: break-word;">
                        <f:facet name="header">
                            <h:outputText value="#{post.datetime}">
                                <f:convertDateTime pattern="HH:mm:ss dd.MM.yyyy"/>
                            </h:outputText>
                        </f:facet>
                        <h:outputText value="#{post.text}"  escape="false"/>
                    </p:panel>
                </p:column>

               <c:if test="#{authorizationBean.user.gid ge 3 || authorizationBean.user == null}">
                 <p:column>
                    <f:facet name="header">
                        <h:outputText value="#{resourcesController.extractResource('RATE')}" />
                    </f:facet>
                    <h:form>
                        <p:rating value="#{post.rate}" 
                                  id="rating"
                                  valueChangeListener="#{forumPostsBean.handleRate}" />
                          
                        <p:commandButton style="padding-left: 5px; font-weight: bolder;margin-top: 10px"
                                  value="#{resourcesController.extractResource('VOTE')}"
                                  async="true"
                                  ajax="false"
                                  action="#{forumPostsBean.updateRate(post)}"/>
                              
                    </h:form>
                 </p:column>
               </c:if>

               <c:if test="#{authorizationBean.user.gid le 2}">
                   <p:column>
                       <f:facet name="header">
                           <h:outputText value="#{resourcesController.extractResource('REMOVAL')}" />
                       </f:facet>
                       
                         <h:commandLink style="padding-left: 5px; font-weight: bolder"
                                  value="#{resourcesController.extractResource('REMOVE')}"
                                  action="#{forumPostsBean.deleteComment(post)}"/>
                       
                   </p:column>
               </c:if>

            </p:dataTable>
        </h:form>
        <h:form>
          <p:growl id="messageGrowl" showDetail="true"/>
          <h:panelGrid columns="1">
              <p:editor width="780"
                        
                        id="newcomment"
                        height="100"
                        required="true"
                        requiredMessage="#{resourcesController.extractResource('NO_COMMENT')}"
                        value="#{forumPostsBean.text}"/>
            <p:commandButton value="#{resourcesController.extractResource('LEAVE_COMMENT')}"
                             style="width:300px"
                             async="true"
                             ajax="false"
                             update="messageGrowl newcomment"
                             action="#{forumPostsBean.leaveComment(authorizationBean.user)}"/>
          </h:panelGrid>
        </h:form>
      </center>

      <ui:insert name="footer" >
			<ui:include src="footer.xhtml" />
      </ui:insert>  
    </h:body>
</html>

